package com.wtktest.business.aop;
import cn.hutool.core.util.StrUtil;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;


@Component
@Aspect
public class BusinessAround {

    @Pointcut("execution(* com.wtktest.business.aop.UserService.*(..)) && args(name, age)")
    public void myPoint(String name,String age){}

    @Pointcut("execution(* com.wtktest.business.aop.UserService.*(..)) && args(name)")
    public void myPoint1(String name){}

    @Around("myPoint1(name)")
    public String around(ProceedingJoinPoint point,String name) throws Throwable {
        Object resultObj = point.proceed();
        System.out.println(
                StrUtil.format("代理around方法{}结束",
                        point.getSignature().getName()
                )
        );
        return resultObj.toString()+"代理对象哦";
    }

    @Before("execution(* com.wtktest.business.aop.BusinessController.*(..))")
    public void before(JoinPoint point) throws Throwable {
        System.out.println("代理--执行前");
    }

    @After("execution(* com.wtktest.business.aop.BusinessController.*(..))")
    public void after(JoinPoint point) throws Throwable {
        System.out.println("代理--执行后");
    }
}
